package demo14;


//T extends Comparable<T>  T一定要实现comparable接口
class Ajg<T extends Comparable<T>>{
    public T findMax(T[] array) {
        T max = array[0];
        for (int i = 0; i < array.length; i++) {
            //max < array[i] error
            if (array[i].compareTo(max) > 0) {
                max = array[i];
            }
        }
        return max;
    }
}
class A implements Comparable<A> {
    @Override
    public int compareTo(A o) {
        return 0;
    }
}

public class Test14 {
    public static void main(String[] args) {
        Ajg<String> ajg = new Ajg<>();
        Ajg<Integer> ajg1 = new Ajg<>();
        Integer[] array = new Integer[]{1,2,3,4,5,6};
        System.out.println(ajg1.findMax(array));
//        Ajg<A> aAjg = new Ajg<>();  报错，A类没有实现Comparable接口
    }
}
